/*
package com.ebring.shareEducation.service.impl;

import com.ebring.shareEducation.bean.CoinOrder;
import com.ebring.shareEducation.bean.CompanyPay;
import com.ebring.shareEducation.bean.User;
import com.ebring.shareEducation.bean.Ustaccount;
import com.ebring.shareEducation.controller.CompanyPayController;
import com.ebring.shareEducation.dao.CoinOrderMapper;
import com.ebring.shareEducation.dao.UserMapper;
import com.ebring.shareEducation.dao.UstAccountMapper;
import com.ebring.shareEducation.dao.WalletAddsMapper;
import com.ebring.shareEducation.service.CoinOrderService;
import com.ebring.shareEducation.service.CompanyPayService;
import com.ebring.shareEducation.service.UserService;
import com.ebring.shareEducation.utils.RspMsg;
import com.ebring.shareEducation.utils.UuidUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

*/
/**
 * Created by Cola
 * Date  2018-12-08 09:48
 *//*


@Service
@Transactional
public class CoinOrderServiceImpl implements CoinOrderService {

    @Autowired
    CoinOrderMapper coinOrderMapper;

    @Autowired
    UserMapper userMapper;

    @Autowired
    UstAccountMapper ustAccountMapper;

    private static Logger logger = LoggerFactory.getLogger(CoinOrderServiceImpl.class);

    // 增加金币记录
    @Override
    public RspMsg addMoney(CoinOrder coinOrder) {
        RspMsg rspMsg = new RspMsg();
        coinOrder.setCoinId("SECP" + UuidUtils.getNumberId(20));
        coinOrder.setPlusOrMinus("1");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        coinOrder.setTradeTime(simpleDateFormat.format(date));
        // 插入操作记录
        int i = coinOrderMapper.insertSelective(coinOrder);
        // 修改用户表
        Ustaccount ustaccount = ustAccountMapper.selectByPrimaryKey(coinOrder.getUserId());
        if (ustaccount.getBalance() == null) {
            ustaccount.setBalance("0");
        }

        Double paygold = Double.parseDouble(ustaccount.getBalance());
        Double i2 = Double.parseDouble(coinOrder.getAmount());
        ustaccount.setBalance(String.valueOf(paygold + i2));
        int i1 = ustAccountMapper.updateByPrimaryKeySelective(ustaccount);
        if (i > 0 && i1 > 0) {
            rspMsg.setOK();
            coinOrder.setRemark("金币增加成功");
            coinOrderMapper.updateByPrimaryKeySelective(coinOrder);
            logger.info("金币增加成功");
            return rspMsg;
        }


        rspMsg.setError();
        rspMsg.setMsg("增加金币记录失败");
        coinOrder.setRemark(rspMsg.getMsg());
        coinOrderMapper.updateByPrimaryKeySelective(coinOrder);
        logger.info("增加金币记录失败");
        return rspMsg;
    }

    // 扣金币记录
    @Override
    public RspMsg minusMoney(CoinOrder coinOrder) {
        RspMsg rspMsg = new RspMsg();
        coinOrder.setCoinId("SECM" + UuidUtils.getNumberId(20));
        coinOrder.setPlusOrMinus("0");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        coinOrder.setTradeTime(simpleDateFormat.format(date));
        // 插入操作记录
        int i = coinOrderMapper.insertSelective(coinOrder);
        // 修改用户表
        Ustaccount ustaccount = ustAccountMapper.selectByPrimaryKey(coinOrder.getUserId());
        if (ustaccount.getBalance() != null) {
            Double paygold = Double.parseDouble(ustaccount.getBalance());
            Double i2 = Double.parseDouble(coinOrder.getAmount());
            if (paygold >= i2) {
                ustaccount.setBalance(String.valueOf(paygold - i2));
                int i1 = ustAccountMapper.updateByPrimaryKeySelective(ustaccount);
                if (i > 0 && i1 > 0) {
                    rspMsg.setOK();
                    coinOrder.setRemark("金币扣款成功");
                    coinOrderMapper.updateByPrimaryKeySelective(coinOrder);
                    logger.info("金币扣款成功!");
                    return rspMsg;
                }
                rspMsg.setError();
                rspMsg.setMsg("扣金币记录失败");
                logger.info("扣金币记录失败");
                coinOrder.setRemark(rspMsg.getMsg());
                coinOrderMapper.updateByPrimaryKeySelective(coinOrder);
                return rspMsg;
            } else {
                rspMsg.setError();
                rspMsg.setMsg("用户所持金币不足，请充值后再操作！");
                logger.info("用户所持金币不足，请充值后再操作！");
                coinOrder.setRemark(rspMsg.getMsg());
                coinOrderMapper.updateByPrimaryKeySelective(coinOrder);
                return rspMsg;
            }
        } else {
            rspMsg.setError();
            rspMsg.setMsg("当前用户没有金币，请先充值！");
            logger.info("当前用户没有金币，请先充值！");
            coinOrder.setRemark(rspMsg.getMsg());
            coinOrderMapper.updateByPrimaryKeySelective(coinOrder);
            return rspMsg;
        }
    }

    // 金币提现
    @Override
    public RspMsg cashMoney(CoinOrder coinOrder) {
        RspMsg rspMsg = new RspMsg();
        coinOrder.setCoinId("SECM" + UuidUtils.getNumberId(20));
        coinOrder.setPlusOrMinus("0");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        coinOrder.setTradeTime(simpleDateFormat.format(date));
        coinOrder.setRemark("金币提现");
        // 插入操作记录
        int i = coinOrderMapper.insertSelective(coinOrder);
        CompanyPayController companyPayController = new CompanyPayController();
        RspMsg<CompanyPay> companyPayRspMsg = companyPayController.coinCash(coinOrder.getUserId(), coinOrder.getAmount(), coinOrder.getCoinId());

        if (companyPayRspMsg.getCode() == 1) {
            rspMsg.setOK();
            logger.info("提现成功！");
            return rspMsg;
        } else {
            rspMsg.setError();
            rspMsg.setMsg("提现失败！");
            logger.info("提现失败！");
            return rspMsg;
        }
    }

    @Override
    public RspMsg coinPaymentWater(String userId) {
        RspMsg rspMsg = new RspMsg<>();
        List<CoinOrder> coinOrders = coinOrderMapper.selectPaymentWater(userId);
        if (coinOrders.size() > 0) {
            rspMsg.setOK();
            rspMsg.setResult(coinOrders);
        } else {
            rspMsg.setError();
            rspMsg.setMsg("查询不到数据!");
        }
        return rspMsg;
    }
}
*/
